package com.itfreer.data.general;

import com.itfreer.data.general.cache.LocalCache;
import com.itfreer.data.general.domain.IDomain;
import com.itfreer.utils.StringUtils;

import java.util.HashMap;

/**
 * 类功能说明 定义定义元数据管理工作空间类 2014.6.5
 */
public class TableFactoryClass implements ITableFactory {

	public static Object LOCA_OBJECT = new Object();

	public static final TableFactoryClass install = new TableFactoryClass();

    private TableFactoryClass(){

    }

	/**
	 * 打开指定结构表
	 */
	public ITable openTable(String metadataTableName) {
		if (StringUtils.IsNullOrSpace(metadataTableName))
			return null;
		metadataTableName = metadataTableName.toUpperCase().trim();
		synchronized (LOCA_OBJECT) {
			if (LocalCache.getTableCache().containsKey(metadataTableName)) {
				ITable pTable = LocalCache.getTableCache().get(metadataTableName);
				return pTable;
			} else {
				return null;
			}
		}
	}

	/**
	 * 打开字典对象
	 */
	@Override
	public IDomain openDomain(String domainTable, String domainName) {
		synchronized (LOCA_OBJECT) {
			HashMap<String, IDomain> domainCache = LocalCache.getDomainCache();
			String key = domainTable + ":" + domainName;
			if(domainCache.containsKey(key)){
				return (IDomain)domainCache.get(key);
			}else{
				return null;
			}
		}
	}
}